# coding=utf-8

import os 
def a():
	path = str(input(">>>"))
	unicde_path = unicode(path,'utf-8')
	dir_folder = os.listdir(unicode_path)
	print(os.pardir() + ":")
	i = None 
	for i in range(len(dir_folder)):
		print(dir_folder[i + 1])
	while True:
		mode = str(input("模式选择:"))
		if mode == "delete":
			filepath = dir_folder[int(input("选择文件:"))] + path
			try:
				os.remove(filepath)
			except OSError:
				print("这是一个文件夹，不支持删除")
		elif mode == "rename":
			filepath = dir_folder[int(input("file.choose:"))] + path
			try:
				os.replase(filepath)
			except OSError:
				print("错误:".format(e))
		elif mode == "creat":
			filename = str(input("输入想要创建的文件名:"))
			try:
				open(filename,'x')
				filename.write(str(input("请输入要写入的内容:")))
			except:
				print("这个文件不是空的，不支持本操作")
		elif mode == "read":
			filename = str(input("请输入要读取文件的文件名:"))
			openmode = str(input("请输入要读取文件的读取模式:"))
			open(filename,openmode)
			if openmode.find("+") != -1 or openmode.find("a") != -1 or openmode.find("ab") != -1 or openmode.find("w") != -1 or openmode.find("wb") != -1:
				filename.write(str(input("请输入要写入的内容:")))
			else:
				filename.read()
		elif mode == "select":
			i = 0
			selectobject = str(input("请选择要查找的文本:"))
			while i <= len(dir_folder):
				if selectobject in dir_folder[i]:
					print("成功,文件名为{}".format(dir_folder[i]))
				else:
					print("未找到文件")
		else:
			print("错误")
			continue
while True:
	a()